// deltaq
// (c) 2010, Normen Müller, normen.mueller@gmail.com  
// $Id$
package deltaq.svn

import java.text.MessageFormat
import java.util.Comparator

import org.tmatesoft.svn.cli.AbstractSVNCommand
import org.tmatesoft.svn.cli.AbstractSVNCommandEnvironment

import scaup.data.Conversions._

object SVNCommandUtil {
  def getVersion(env: AbstractSVNCommandEnvironment, quiet: Boolean) =    
    if (quiet)
      DeltaQ.VERSION
    else
      MessageFormat.format(env.getProgramName + ", version {0}\n", Array[Object](DeltaQ.VERSION): _*) +
      "\nCopyright (c) 2010 Normen Mueller.\n" +
      "DeltaQ is open source (LGPL) software, see http://code.google.com/p/deltaq/ for more information.\n" +
      "DeltaQ is a Java/Scala version of Subversion, see http://subversion.tigris.org/"
  
  def getGenericHelp(programName: String, header: String, footer: String, commandComparator: java.util.Comparator[AbstractSVNCommand]) = {
    val help = new StringBuilder
    if (header != null)
      help.append(MessageFormat.format(header, Array[Object](programName, DeltaQ.VERSION): _*))
    
    for (command <- AbstractSVNCommand.availableCommands(commandComparator).asInstanceOf[java.util.Iterator[AbstractSVNCommand]]) {
      help.append("\n   ")
      help.append(command.getName)
      if (command.getAliases.length > 0) {
        help.append(" (")
        for (i <- 0 until command.getAliases.length) {
          help.append(command.getAliases()(i))
          if (i + 1 < command.getAliases.length)
            help.append(", ");
        }
        help.append(")");
      }
    }
    
    help.append("\n\n");
    if (footer != null)
      help.append(footer)            
    help.toString()
  }
}
